package cn.itcast.springdata.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

/**
 * @ClassName StringDemo
 * @Description 测试hash数据结构
 * @Author 传智播客
 * @Date 17:09 2019/5/9
 * @Version 2.1
 **/
@ContextConfiguration(locations = {"classpath:applicationContext-redis.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class HashDemo {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * @author 栗子
     * @Description 原生：hset key (map)filed value
     * @Date 17:20 2019/5/9
     * @param
     * @return void
     **/
    @Test
    public void testSaveOrUpdateForHash(){
        redisTemplate.boundHashOps("user").put("name","栗子");
        redisTemplate.boundHashOps("user").put("school","南昌大学软件学院");
        redisTemplate.boundHashOps("user").put("address","青山湖校区");
    }

    /**
     * @author 栗子
     * @Description 获取数据
     * @Date 17:24 2019/5/9
     * @param
     * @return void
     **/
    @Test
    public void testGetValueForHash(){
        System.out.println("name:"+redisTemplate.boundHashOps("user").get("name"));
        System.out.println("school:"+redisTemplate.boundHashOps("user").get("school"));
        System.out.println("address:"+redisTemplate.boundHashOps("user").get("address"));
    }

}
